In-class_Ex4

Overview

  • performing geocoding using data downloaded from data.gov.sg

  • calibrating Geographically Weighted Poisson Regression

Getting Started

pacman::p_load(sf, sfdep, tmap, tidyverse, knitr, plotly, httr, dplyr)

Geocoding using SLA API

Geocoding - process of aspatial description of a location e.g. address

url <- "https://www.onemap.gov.sg/api/common/elastic/search"
csv <- read_csv("Data/Aspatial/Generalinformationofschools.csv")
Rows: 346 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (31): school_name, url_address, address, postal_code, telephone_no, tele...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
postcodes <- csv$`postal_code`

found <- data.frame()
not_found <- data.frame()

for(postcode in postcodes){
  query<-list('searchVal'=postcode,'returnGeom'='Y','getAddrDetails'='Y', 'pageNum'='1')
  res <- GET(url,query=query)
  
  if((content(res)$found)!=0){
    found <- rbind(found, data.frame(content(res))[4:13])
  } else{
    not_found = data.frame(postcode)
  }
}
merged = merge(csv, found, by.x= 'postal_code', by.y = 'results.POSTAL', all=TRUE)
write.csv(merged, file = "Data/Aspatial/schools.csv")
write.csv(not_found, file = "Data/Aspatial/not_found.csv")

Importing geospatial data

mpsz <- st_read(dsn = "Data/Geospatial",
                layer = "MPSZ-2019") %>%
  st_transform(crs = 3414)
Reading layer `MPSZ-2019' from data source 
  `/Users/youting/ytquek/ISSS624/In-class Exercise/In-class Exercise 4/Data/Geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 332 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
Geodetic CRS:  WGS 84

Importing & tidying school data

schools <- read_csv("Data/Aspatial/Generalinformationofschools.csv")
Rows: 346 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (31): school_name, url_address, address, postal_code, telephone_no, tele...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Note: Zhenghua Secondary School missing. Manually update latitude and longitude for ZHENGHUA SECONDARY SCHOOL

  • Latitude: 1.389279

  • Longitude: 103.7651

merged <- merged %>%
  mutate(
    results.LATITUDE = ifelse(school_name == "ZHENGHUA SECONDARY SCHOOL", 1.389279, results.LATITUDE),
    results.LONGITUDE = ifelse(school_name == "ZHENGHUA SECONDARY SCHOOL", 103.7651, results.LONGITUDE)
  )
schools <- merged %>%
  rename(latitude = "results.LATITUDE", longitude = "results.LONGITUDE") %>%
  select(postal_code, school_name, latitude, longitude)

Note: schools is a tibble dataframe object class

Converting an aspatial data into a simple features tibble data.frame

schools_sf <- st_as_sf(schools,
                       coords = c("longitude", "latitude"),
                       crs =4326) %>%
  st_transform(crs = 3414)

Plotting a point simple feature layer

#| code-fold: true
#| code-sumary: "Show the code chunk"
tmap_mode("view")
tmap mode set to interactive viewing
tm_shape(schools_sf) +
  tm_dots() +
tm_view(set.zoom.limits = c(11,14))
tmap_mode("plot")
tmap mode set to plotting

Preparing

mpsz$`SCHOOL_COUNT` <- lengths(
  st_intersects(
    mpsz, schools_sf
  )
)

Summary statistics

summary(mpsz$SCHOOL_COUNT)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   0.000   0.000   1.054   2.000  12.000 
business_sf <- st_read(dsn = "data/geospatial", layer = "Business") %>%
  st_transform(crs = 3414)
Reading layer `Business' from data source 
  `/Users/youting/ytquek/ISSS624/In-class Exercise/In-class Exercise 4/Data/Geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 6550 features and 3 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 3669.148 ymin: 25408.41 xmax: 47034.83 ymax: 50148.54
Projected CRS: SVY21 / Singapore TM
tmap_options(check.and.fix = TRUE)
tm_shape(mpsz) +
  tm_polygons() +
tm_shape(business_sf) +
  tm_dots()
Warning: The shape mpsz is invalid. See sf::st_is_valid

Data Integration and Wrangling

Import the rds file into R environment

flow_data <- read_rds("data/rds/flow_data_tidy.rds") 
flow_data$FlowNoIntra <- ifelse(
  flow_data$ORIGIN_SZ == flow_data$DESTIN_SZ,
  0, flow_data$MORNING_PEAK)
flow_data$offset <- ifelse(
  flow_data$ORIGIN_SZ == flow_data$DESTIN_SZ,
  0.000001, 1)
flow_data <- flow_data %>%
  filter(FlowNoIntra > 0)
inter_zonal_flow <- flow_data %>%
  rename(TRIPS =MORNING_PEAK,
         DIST = dist)

Model Calibration

pacman::p_load(sp, DT, stplanr,
               performance, reshape2,
               ggpubr, units)

Unconstrained SIM

uncSIM <- glm(formula = TRIPS ~ 
                log(SCHOOL_COUNT) + 
                log(RETAIL_COUNT) +
                log(DIST),
              family = poisson(link = "log"),
              data = inter_zonal_flow,
              na.action = na.exclude)
uncSIM

Call:  glm(formula = TRIPS ~ log(SCHOOL_COUNT) + log(RETAIL_COUNT) + 
    log(DIST), family = poisson(link = "log"), data = inter_zonal_flow, 
    na.action = na.exclude)

Coefficients:
      (Intercept)  log(SCHOOL_COUNT)  log(RETAIL_COUNT)          log(DIST)  
          18.8651             0.7492             0.2050            -1.5751  

Degrees of Freedom: 14470 Total (i.e. Null);  14467 Residual
Null Deviance:      47090000 
Residual Deviance: 25940000     AIC: 26030000

Goodness-of-Fit

CalcRSquared <- function(observed,estimated){
  r <- cor(observed,estimated)
  R2 <- r^2
  R2
}
CalcRSquared(uncSIM$data$TRIPS, uncSIM$fitted.values)
[1] 0.1591336
r2_mcfadden(uncSIM)
# R2 for Generalized Linear Regression
       R2: 0.448
  adj. R2: 0.448

Origin constrained SIM

orcSIM <- glm(formula = TRIPS ~
                ORIGIN_SZ +
                log(SCHOOL_COUNT) +
                log(RETAIL_COUNT) +
                log(DIST) - 1,
              family = poisson(link = "log"),
              data = inter_zonal_flow,
              na.action = na.exclude)
summary(orcSIM)

Call:
glm(formula = TRIPS ~ ORIGIN_SZ + log(SCHOOL_COUNT) + log(RETAIL_COUNT) + 
    log(DIST) - 1, family = poisson(link = "log"), data = inter_zonal_flow, 
    na.action = na.exclude)

Coefficients:
                    Estimate Std. Error  z value Pr(>|z|)    
ORIGIN_SZAMSZ01   19.8739840  0.0047627  4172.84   <2e-16 ***
ORIGIN_SZAMSZ02   20.5902203  0.0042786  4812.33   <2e-16 ***
ORIGIN_SZAMSZ03   20.2327026  0.0045531  4443.70   <2e-16 ***
ORIGIN_SZAMSZ04   19.7744438  0.0049837  3967.79   <2e-16 ***
ORIGIN_SZAMSZ05   19.6574529  0.0056396  3485.61   <2e-16 ***
ORIGIN_SZAMSZ06   19.9659115  0.0048946  4079.16   <2e-16 ***
ORIGIN_SZAMSZ07   18.6746164  0.0096316  1938.90   <2e-16 ***
ORIGIN_SZAMSZ08   19.2701601  0.0090776  2122.82   <2e-16 ***
ORIGIN_SZAMSZ09   19.9889467  0.0052858  3781.64   <2e-16 ***
ORIGIN_SZAMSZ10   20.3422035  0.0045778  4443.62   <2e-16 ***
ORIGIN_SZAMSZ11   18.3944113  0.0129212  1423.58   <2e-16 ***
ORIGIN_SZAMSZ12   18.3484209  0.0109652  1673.33   <2e-16 ***
ORIGIN_SZBDSZ01   20.9668587  0.0043388  4832.36   <2e-16 ***
ORIGIN_SZBDSZ02   20.4059518  0.0050601  4032.75   <2e-16 ***
ORIGIN_SZBDSZ03   20.6725514  0.0045276  4565.93   <2e-16 ***
ORIGIN_SZBDSZ04   21.6703853  0.0038930  5566.44   <2e-16 ***
ORIGIN_SZBDSZ05   20.7497445  0.0046085  4502.46   <2e-16 ***
ORIGIN_SZBDSZ06   20.9119361  0.0046432  4503.77   <2e-16 ***
ORIGIN_SZBDSZ07   18.9749815  0.0097896  1938.28   <2e-16 ***
ORIGIN_SZBDSZ08   19.1933901  0.0091312  2101.95   <2e-16 ***
ORIGIN_SZBKSZ01   19.5422606  0.0064732  3018.96   <2e-16 ***
ORIGIN_SZBKSZ02   20.1748913  0.0050076  4028.89   <2e-16 ***
ORIGIN_SZBKSZ03   20.3984624  0.0047226  4319.35   <2e-16 ***
ORIGIN_SZBKSZ04   19.6182212  0.0059652  3288.76   <2e-16 ***
ORIGIN_SZBKSZ05   19.6033818  0.0063181  3102.74   <2e-16 ***
ORIGIN_SZBKSZ06   19.7145224  0.0056372  3497.20   <2e-16 ***
ORIGIN_SZBKSZ07   20.4237448  0.0041912  4873.03   <2e-16 ***
ORIGIN_SZBKSZ08   19.7992538  0.0050405  3928.02   <2e-16 ***
ORIGIN_SZBKSZ09   19.7821586  0.0055558  3560.66   <2e-16 ***
ORIGIN_SZBLSZ01   17.7977276  0.0149058  1194.01   <2e-16 ***
ORIGIN_SZBLSZ02   17.4287491  0.0192364   906.03   <2e-16 ***
ORIGIN_SZBLSZ03   16.5884288  0.0459848   360.74   <2e-16 ***
ORIGIN_SZBLSZ04   17.7851626  0.0232823   763.89   <2e-16 ***
ORIGIN_SZBMSZ01   20.0751840  0.0052887  3795.89   <2e-16 ***
ORIGIN_SZBMSZ02   18.6956140  0.0066656  2804.80   <2e-16 ***
ORIGIN_SZBMSZ03   19.3204425  0.0054755  3528.56   <2e-16 ***
ORIGIN_SZBMSZ04   19.4724220  0.0049390  3942.59   <2e-16 ***
ORIGIN_SZBMSZ05   16.9581801  0.0168804  1004.61   <2e-16 ***
ORIGIN_SZBMSZ06   16.9898638  0.0181852   934.27   <2e-16 ***
ORIGIN_SZBMSZ07   19.2868403  0.0056231  3429.91   <2e-16 ***
ORIGIN_SZBMSZ08   19.1477543  0.0055918  3424.28   <2e-16 ***
ORIGIN_SZBMSZ09   18.7564539  0.0086298  2173.46   <2e-16 ***
ORIGIN_SZBMSZ10   18.3617854  0.0089250  2057.35   <2e-16 ***
ORIGIN_SZBMSZ11   18.9167941  0.0063340  2986.54   <2e-16 ***
ORIGIN_SZBMSZ12   18.7874661  0.0093024  2019.63   <2e-16 ***
ORIGIN_SZBMSZ13   19.5654046  0.0057517  3401.70   <2e-16 ***
ORIGIN_SZBMSZ14   19.0685619  0.0063346  3010.24   <2e-16 ***
ORIGIN_SZBMSZ15   19.4403124  0.0058147  3343.30   <2e-16 ***
ORIGIN_SZBMSZ16   18.4469203  0.0092638  1991.28   <2e-16 ***
ORIGIN_SZBMSZ17   18.3430175  0.0157692  1163.22   <2e-16 ***
ORIGIN_SZBPSZ01   20.1806714  0.0053660  3760.81   <2e-16 ***
ORIGIN_SZBPSZ02   19.8116707  0.0061485  3222.19   <2e-16 ***
ORIGIN_SZBPSZ03   19.8467602  0.0059769  3320.57   <2e-16 ***
ORIGIN_SZBPSZ04   20.4613200  0.0048398  4227.72   <2e-16 ***
ORIGIN_SZBPSZ05   20.5379711  0.0043769  4692.39   <2e-16 ***
ORIGIN_SZBPSZ06   18.8948034  0.0093668  2017.21   <2e-16 ***
ORIGIN_SZBPSZ07   19.4104568  0.0087961  2206.70   <2e-16 ***
ORIGIN_SZBSSZ01   20.0139503  0.0056561  3538.45   <2e-16 ***
ORIGIN_SZBSSZ02   20.2543885  0.0047198  4291.38   <2e-16 ***
ORIGIN_SZBSSZ03   19.5428803  0.0052713  3707.41   <2e-16 ***
ORIGIN_SZBTSZ01   20.0198045  0.0058541  3419.77   <2e-16 ***
ORIGIN_SZBTSZ02   19.3618525  0.0081472  2376.51   <2e-16 ***
ORIGIN_SZBTSZ03   19.5883853  0.0068935  2841.59   <2e-16 ***
ORIGIN_SZBTSZ04   18.7720238  0.0103909  1806.58   <2e-16 ***
ORIGIN_SZBTSZ05   18.8069026  0.0120628  1559.08   <2e-16 ***
ORIGIN_SZBTSZ06   18.7068633  0.0094575  1978.00   <2e-16 ***
ORIGIN_SZBTSZ07   17.6292257  0.0141551  1245.43   <2e-16 ***
ORIGIN_SZBTSZ08   18.6989374  0.0109610  1705.94   <2e-16 ***
ORIGIN_SZCBSZ01   18.2189868  0.0548317   332.27   <2e-16 ***
ORIGIN_SZCCSZ01   18.9734563  0.0139450  1360.59   <2e-16 ***
ORIGIN_SZCHSZ01   19.5955119  0.0121035  1619.00   <2e-16 ***
ORIGIN_SZCHSZ02   19.3320960  0.0081620  2368.55   <2e-16 ***
ORIGIN_SZCHSZ03   21.2164518  0.0063552  3338.43   <2e-16 ***
ORIGIN_SZCKSZ01   20.1046845  0.0049333  4075.29   <2e-16 ***
ORIGIN_SZCKSZ02   20.5371946  0.0050256  4086.53   <2e-16 ***
ORIGIN_SZCKSZ03   20.7210560  0.0042184  4912.07   <2e-16 ***
ORIGIN_SZCKSZ04   21.4013886  0.0042524  5032.80   <2e-16 ***
ORIGIN_SZCKSZ05   20.9413146  0.0049434  4236.18   <2e-16 ***
ORIGIN_SZCKSZ06   20.2557727  0.0071832  2819.88   <2e-16 ***
ORIGIN_SZCLSZ01   19.3383703  0.0076634  2523.46   <2e-16 ***
ORIGIN_SZCLSZ02   18.5226956  0.0135522  1366.77   <2e-16 ***
ORIGIN_SZCLSZ03   19.0225512  0.0080145  2373.51   <2e-16 ***
ORIGIN_SZCLSZ04   20.7981505  0.0042400  4905.22   <2e-16 ***
ORIGIN_SZCLSZ05   18.3015625  0.0146815  1246.58   <2e-16 ***
ORIGIN_SZCLSZ06   20.8207386  0.0039567  5262.09   <2e-16 ***
ORIGIN_SZCLSZ07   19.6728958  0.0054199  3629.76   <2e-16 ***
ORIGIN_SZCLSZ08   20.0851929  0.0056956  3526.43   <2e-16 ***
ORIGIN_SZCLSZ09   18.5749589  0.0165415  1122.93   <2e-16 ***
ORIGIN_SZDTSZ02   15.8276209  0.0833992   189.78   <2e-16 ***
ORIGIN_SZDTSZ03   16.2512838  0.0737972   220.22   <2e-16 ***
ORIGIN_SZDTSZ13   16.7744385  0.0312450   536.87   <2e-16 ***
ORIGIN_SZGLSZ01   18.2368248  0.0096104  1897.62   <2e-16 ***
ORIGIN_SZGLSZ02   19.8705255  0.0049014  4054.06   <2e-16 ***
ORIGIN_SZGLSZ03   19.8249435  0.0053109  3732.85   <2e-16 ***
ORIGIN_SZGLSZ04   20.7800335  0.0041261  5036.20   <2e-16 ***
ORIGIN_SZGLSZ05   20.6040494  0.0043049  4786.23   <2e-16 ***
ORIGIN_SZHGSZ01   20.0273475  0.0044824  4468.04   <2e-16 ***
ORIGIN_SZHGSZ02   20.2480656  0.0044575  4542.47   <2e-16 ***
ORIGIN_SZHGSZ03   20.0756442  0.0049003  4096.81   <2e-16 ***
ORIGIN_SZHGSZ04   20.7577748  0.0040465  5129.84   <2e-16 ***
ORIGIN_SZHGSZ05   20.9779992  0.0040123  5228.42   <2e-16 ***
ORIGIN_SZHGSZ06   19.7403058  0.0054229  3640.20   <2e-16 ***
ORIGIN_SZHGSZ07   20.1896268  0.0046051  4384.22   <2e-16 ***
ORIGIN_SZHGSZ08   19.8646492  0.0052403  3790.72   <2e-16 ***
ORIGIN_SZHGSZ09   18.3647736  0.0069196  2654.04   <2e-16 ***
ORIGIN_SZHGSZ10   16.8720475  0.0421046   400.72   <2e-16 ***
ORIGIN_SZJESZ01   20.2673794  0.0046723  4337.79   <2e-16 ***
ORIGIN_SZJESZ02   20.0595982  0.0046503  4313.61   <2e-16 ***
ORIGIN_SZJESZ03   19.9128778  0.0049848  3994.75   <2e-16 ***
ORIGIN_SZJESZ04   18.5053667  0.0099227  1864.94   <2e-16 ***
ORIGIN_SZJESZ05   17.8172930  0.0138840  1283.29   <2e-16 ***
ORIGIN_SZJESZ06   20.0124157  0.0045009  4446.36   <2e-16 ***
ORIGIN_SZJESZ07   18.1821423  0.0117267  1550.49   <2e-16 ***
ORIGIN_SZJESZ08   18.8713046  0.0116456  1620.46   <2e-16 ***
ORIGIN_SZJESZ09   20.5535527  0.0048456  4241.72   <2e-16 ***
ORIGIN_SZJESZ10   18.4922322  0.0191243   966.95   <2e-16 ***
ORIGIN_SZJESZ11   18.2891211  0.0197114   927.85   <2e-16 ***
ORIGIN_SZJWSZ01   20.4912737  0.0063102  3247.35   <2e-16 ***
ORIGIN_SZJWSZ02   20.8236694  0.0042249  4928.82   <2e-16 ***
ORIGIN_SZJWSZ03   21.2587613  0.0039733  5350.40   <2e-16 ***
ORIGIN_SZJWSZ04   20.3816464  0.0046199  4411.67   <2e-16 ***
ORIGIN_SZJWSZ05   18.0607448  0.0128857  1401.61   <2e-16 ***
ORIGIN_SZJWSZ06   18.7015202  0.0107614  1737.83   <2e-16 ***
ORIGIN_SZJWSZ07   17.3991822  0.0277096   627.91   <2e-16 ***
ORIGIN_SZJWSZ08   21.8044465  0.0037356  5836.95   <2e-16 ***
ORIGIN_SZJWSZ09   21.5414930  0.0036033  5978.19   <2e-16 ***
ORIGIN_SZKLSZ01   20.0307712  0.0047868  4184.59   <2e-16 ***
ORIGIN_SZKLSZ02   19.0634769  0.0062318  3059.05   <2e-16 ***
ORIGIN_SZKLSZ03   19.2685700  0.0057172  3370.25   <2e-16 ***
ORIGIN_SZKLSZ04   17.7085067  0.0119809  1478.06   <2e-16 ***
ORIGIN_SZKLSZ05   18.6384471  0.0107596  1732.26   <2e-16 ***
ORIGIN_SZKLSZ06   13.7280296  0.1857160    73.92   <2e-16 ***
ORIGIN_SZKLSZ07   18.6425146  0.0084952  2194.47   <2e-16 ***
ORIGIN_SZKLSZ08   18.0928506  0.0101567  1781.37   <2e-16 ***
ORIGIN_SZLKSZ01   17.8907138  0.0397083   450.55   <2e-16 ***
ORIGIN_SZMDSZ01   18.7605188  0.0285455   657.22   <2e-16 ***
ORIGIN_SZMDSZ02   19.1533927  0.0102815  1862.90   <2e-16 ***
ORIGIN_SZMDSZ03   17.8404982  0.0169690  1051.36   <2e-16 ***
ORIGIN_SZMPSZ01   19.0765941  0.0083937  2272.74   <2e-16 ***
ORIGIN_SZMPSZ02   19.2162527  0.0068331  2812.24   <2e-16 ***
ORIGIN_SZMPSZ03   19.9965344  0.0054569  3664.44   <2e-16 ***
ORIGIN_SZMUSZ02   15.9130765  0.1037472   153.38   <2e-16 ***
ORIGIN_SZNTSZ01   17.0840999  0.0352513   484.64   <2e-16 ***
ORIGIN_SZNTSZ02   16.5792122  0.0233186   710.99   <2e-16 ***
ORIGIN_SZNTSZ03   18.9506415  0.0075957  2494.93   <2e-16 ***
ORIGIN_SZNTSZ05   15.8770261  0.0495825   320.21   <2e-16 ***
ORIGIN_SZNTSZ06   15.3997415  0.0557029   276.46   <2e-16 ***
ORIGIN_SZNVSZ01   20.2241694  0.0043487  4650.65   <2e-16 ***
ORIGIN_SZNVSZ02   19.1897826  0.0065383  2934.97   <2e-16 ***
ORIGIN_SZNVSZ03   18.8854268  0.0080459  2347.22   <2e-16 ***
ORIGIN_SZNVSZ04   18.8940191  0.0090985  2076.61   <2e-16 ***
ORIGIN_SZNVSZ05   17.6278585  0.0168107  1048.61   <2e-16 ***
ORIGIN_SZPGSZ01   19.4825220  0.0122960  1584.46   <2e-16 ***
ORIGIN_SZPGSZ02   19.4726761  0.0073116  2663.25   <2e-16 ***
ORIGIN_SZPGSZ03   20.5515713  0.0045631  4503.86   <2e-16 ***
ORIGIN_SZPGSZ04   21.0527131  0.0041500  5072.89   <2e-16 ***
ORIGIN_SZPGSZ05   20.1436604  0.0057267  3517.48   <2e-16 ***
ORIGIN_SZPLSZ01   19.1832002  0.0120006  1598.53   <2e-16 ***
ORIGIN_SZPLSZ02   18.8752206  0.0149740  1260.53   <2e-16 ***
ORIGIN_SZPLSZ03   18.1000818  0.0371769   486.86   <2e-16 ***
ORIGIN_SZPLSZ04   17.1730559  0.0370280   463.79   <2e-16 ***
ORIGIN_SZPLSZ05   17.9084439  0.0225031   795.82   <2e-16 ***
ORIGIN_SZPNSZ01   21.0804425  0.0044829  4702.41   <2e-16 ***
ORIGIN_SZPNSZ02   19.8822123  0.0111507  1783.05   <2e-16 ***
ORIGIN_SZPNSZ03   17.9293289  0.0193571   926.24   <2e-16 ***
ORIGIN_SZPNSZ04   17.1039594  0.0334954   510.64   <2e-16 ***
ORIGIN_SZPNSZ05   18.2543864  0.0275554   662.46   <2e-16 ***
ORIGIN_SZPRSZ01   19.8777935  0.0117586  1690.49   <2e-16 ***
ORIGIN_SZPRSZ02   21.0751780  0.0044832  4700.88   <2e-16 ***
ORIGIN_SZPRSZ03   20.6717019  0.0045577  4535.55   <2e-16 ***
ORIGIN_SZPRSZ04   19.6365125  0.0074923  2620.90   <2e-16 ***
ORIGIN_SZPRSZ05   21.3132151  0.0042119  5060.24   <2e-16 ***
ORIGIN_SZPRSZ06   18.9314574  0.0117278  1614.24   <2e-16 ***
ORIGIN_SZPRSZ07   17.2822918  0.0162430  1063.98   <2e-16 ***
ORIGIN_SZPRSZ08   19.9267642  0.0062298  3198.62   <2e-16 ***
ORIGIN_SZQTSZ01   19.7357175  0.0066359  2974.08   <2e-16 ***
ORIGIN_SZQTSZ02   19.2082141  0.0061402  3128.26   <2e-16 ***
ORIGIN_SZQTSZ03   19.7771883  0.0056220  3517.83   <2e-16 ***
ORIGIN_SZQTSZ04   18.7114421  0.0072842  2568.76   <2e-16 ***
ORIGIN_SZQTSZ05   19.3049324  0.0062401  3093.69   <2e-16 ***
ORIGIN_SZQTSZ06   19.2643228  0.0065590  2937.09   <2e-16 ***
ORIGIN_SZQTSZ07   18.5697347  0.0095373  1947.06   <2e-16 ***
ORIGIN_SZQTSZ08   19.6147001  0.0061330  3198.21   <2e-16 ***
ORIGIN_SZQTSZ09   19.2550793  0.0069947  2752.82   <2e-16 ***
ORIGIN_SZQTSZ10   19.5801866  0.0064513  3035.07   <2e-16 ***
ORIGIN_SZQTSZ11   17.7398366  0.0143648  1234.95   <2e-16 ***
ORIGIN_SZQTSZ12   17.2420354  0.0186736   923.34   <2e-16 ***
ORIGIN_SZQTSZ13   19.3857418  0.0078878  2457.69   <2e-16 ***
ORIGIN_SZQTSZ14   18.1300753  0.0122096  1484.90   <2e-16 ***
ORIGIN_SZQTSZ15   19.4222283  0.0120871  1606.86   <2e-16 ***
ORIGIN_SZRCSZ01   18.1549045  0.0125108  1451.13   <2e-16 ***
ORIGIN_SZRCSZ06   18.8836400  0.0082161  2298.38   <2e-16 ***
ORIGIN_SZRVSZ01   16.7864438  0.0323796   518.43   <2e-16 ***
ORIGIN_SZRVSZ02   16.4203244  0.0276836   593.14   <2e-16 ***
ORIGIN_SZRVSZ03   16.6453738  0.0244992   679.42   <2e-16 ***
ORIGIN_SZRVSZ04   15.9559213  0.0556344   286.80   <2e-16 ***
ORIGIN_SZRVSZ05   17.0476331  0.0164122  1038.71   <2e-16 ***
ORIGIN_SZSBSZ01   20.0417968  0.0062488  3207.29   <2e-16 ***
ORIGIN_SZSBSZ02   19.1869565  0.0081051  2367.26   <2e-16 ***
ORIGIN_SZSBSZ03   20.5769861  0.0045108  4561.70   <2e-16 ***
ORIGIN_SZSBSZ04   20.5154199  0.0050548  4058.57   <2e-16 ***
ORIGIN_SZSBSZ05   19.6250669  0.0065562  2993.35   <2e-16 ***
ORIGIN_SZSBSZ06   18.8419757  0.0171135  1101.00   <2e-16 ***
ORIGIN_SZSBSZ07   19.4897259  0.0124528  1565.09   <2e-16 ***
ORIGIN_SZSBSZ08   18.7027917  0.0140545  1330.73   <2e-16 ***
ORIGIN_SZSBSZ09   18.8893480  0.0088571  2132.67   <2e-16 ***
ORIGIN_SZSESZ02   20.8962192  0.0041665  5015.34   <2e-16 ***
ORIGIN_SZSESZ03   20.9452771  0.0039737  5270.94   <2e-16 ***
ORIGIN_SZSESZ04   20.6576142  0.0046364  4455.55   <2e-16 ***
ORIGIN_SZSESZ05   19.5170732  0.0058912  3312.92   <2e-16 ***
ORIGIN_SZSESZ06   20.7595824  0.0045747  4537.89   <2e-16 ***
ORIGIN_SZSESZ07   17.6888256  0.0195787   903.47   <2e-16 ***
ORIGIN_SZSGSZ01   19.1359250  0.0085781  2230.79   <2e-16 ***
ORIGIN_SZSGSZ02   18.5614369  0.0102037  1819.10   <2e-16 ***
ORIGIN_SZSGSZ03   19.9933176  0.0050434  3964.23   <2e-16 ***
ORIGIN_SZSGSZ04   20.2426871  0.0047211  4287.71   <2e-16 ***
ORIGIN_SZSGSZ05   18.0114965  0.0107743  1671.70   <2e-16 ***
ORIGIN_SZSGSZ06   20.2593194  0.0044538  4548.76   <2e-16 ***
ORIGIN_SZSGSZ07   19.0763664  0.0062968  3029.54   <2e-16 ***
ORIGIN_SZSKSZ01   19.9222451  0.0085136  2340.04   <2e-16 ***
ORIGIN_SZSKSZ02   20.8633383  0.0055248  3776.33   <2e-16 ***
ORIGIN_SZSKSZ03   19.6528148  0.0080534  2440.33   <2e-16 ***
ORIGIN_SZSKSZ04   18.0754470  0.0275771   655.45   <2e-16 ***
ORIGIN_SZSKSZ05   19.1192521  0.0155579  1228.91   <2e-16 ***
ORIGIN_SZSLSZ01   17.1501034  0.0329384   520.67   <2e-16 ***
ORIGIN_SZSLSZ04   19.5949774  0.0076753  2552.98   <2e-16 ***
ORIGIN_SZSRSZ01   16.9761403  0.0162020  1047.78   <2e-16 ***
ORIGIN_SZTHSZ01   17.9695687  0.0488559   367.81   <2e-16 ***
ORIGIN_SZTHSZ03   18.5427522  0.0223617   829.22   <2e-16 ***
ORIGIN_SZTHSZ04   17.4760374  0.0286247   610.52   <2e-16 ***
ORIGIN_SZTHSZ06   17.8401186  0.0183322   973.16   <2e-16 ***
ORIGIN_SZTMSZ01   20.3406361  0.0056607  3593.33   <2e-16 ***
ORIGIN_SZTMSZ02   22.0307026  0.0037386  5892.85   <2e-16 ***
ORIGIN_SZTMSZ03   21.3451920  0.0040606  5256.65   <2e-16 ***
ORIGIN_SZTMSZ04   20.6611593  0.0049896  4140.87   <2e-16 ***
ORIGIN_SZTMSZ05   19.3323133  0.0112868  1712.82   <2e-16 ***
ORIGIN_SZTNSZ01   17.9513571  0.0128266  1399.54   <2e-16 ***
ORIGIN_SZTNSZ02   18.0267387  0.0098372  1832.51   <2e-16 ***
ORIGIN_SZTNSZ03   17.7253700  0.0134668  1316.23   <2e-16 ***
ORIGIN_SZTNSZ04   19.4474075  0.0073760  2636.59   <2e-16 ***
ORIGIN_SZTPSZ01   19.1078631  0.0065635  2911.25   <2e-16 ***
ORIGIN_SZTPSZ02   20.2837634  0.0041411  4898.18   <2e-16 ***
ORIGIN_SZTPSZ03   19.1838238  0.0059552  3221.37   <2e-16 ***
ORIGIN_SZTPSZ04   19.1805388  0.0054778  3501.53   <2e-16 ***
ORIGIN_SZTPSZ05   19.3718076  0.0058610  3305.18   <2e-16 ***
ORIGIN_SZTPSZ06   19.6605723  0.0054968  3576.70   <2e-16 ***
ORIGIN_SZTPSZ07   19.4499807  0.0060491  3215.36   <2e-16 ***
ORIGIN_SZTPSZ08   18.7996538  0.0095757  1963.28   <2e-16 ***
ORIGIN_SZTPSZ09   19.0025110  0.0067068  2833.31   <2e-16 ***
ORIGIN_SZTPSZ10   18.8899657  0.0076094  2482.46   <2e-16 ***
ORIGIN_SZTPSZ11   19.6277780  0.0053983  3635.93   <2e-16 ***
ORIGIN_SZTPSZ12   19.1471104  0.0065742  2912.45   <2e-16 ***
ORIGIN_SZTSSZ01   17.4901113  0.0478954   365.17   <2e-16 ***
ORIGIN_SZTSSZ02   20.4997466  0.0081850  2504.55   <2e-16 ***
ORIGIN_SZTSSZ03   20.1076553  0.0084728  2373.19   <2e-16 ***
ORIGIN_SZTSSZ04   20.0646610  0.0089008  2254.26   <2e-16 ***
ORIGIN_SZTSSZ05   19.3962067  0.0151392  1281.19   <2e-16 ***
ORIGIN_SZTSSZ06   20.9235857  0.0178278  1173.65   <2e-16 ***
ORIGIN_SZWCSZ01   20.8411600  0.0086519  2408.86   <2e-16 ***
ORIGIN_SZWCSZ02   17.7355404  0.0328889   539.26   <2e-16 ***
ORIGIN_SZWCSZ03   14.9380886  0.1240699   120.40   <2e-16 ***
ORIGIN_SZWDSZ01   21.1969012  0.0037830  5603.23   <2e-16 ***
ORIGIN_SZWDSZ02   20.5930001  0.0044572  4620.13   <2e-16 ***
ORIGIN_SZWDSZ03   21.2521867  0.0041672  5099.85   <2e-16 ***
ORIGIN_SZWDSZ04   21.0702687  0.0048648  4331.13   <2e-16 ***
ORIGIN_SZWDSZ05   20.4008998  0.0051801  3938.35   <2e-16 ***
ORIGIN_SZWDSZ06   20.6669176  0.0049280  4193.78   <2e-16 ***
ORIGIN_SZWDSZ07   19.0500370  0.0082729  2302.71   <2e-16 ***
ORIGIN_SZWDSZ08   19.0816252  0.0080667  2365.49   <2e-16 ***
ORIGIN_SZWDSZ09   21.4182096  0.0040391  5302.73   <2e-16 ***
ORIGIN_SZYSSZ01   19.5355157  0.0057540  3395.14   <2e-16 ***
ORIGIN_SZYSSZ02   20.8737972  0.0048278  4323.64   <2e-16 ***
ORIGIN_SZYSSZ03   21.6614437  0.0040011  5413.81   <2e-16 ***
ORIGIN_SZYSSZ04   20.9305289  0.0043595  4801.10   <2e-16 ***
ORIGIN_SZYSSZ05   20.1727678  0.0058466  3450.34   <2e-16 ***
ORIGIN_SZYSSZ06   19.1481507  0.0116724  1640.47   <2e-16 ***
ORIGIN_SZYSSZ07   18.7919074  0.0141636  1326.78   <2e-16 ***
ORIGIN_SZYSSZ08   19.9733515  0.0061229  3262.07   <2e-16 ***
ORIGIN_SZYSSZ09   20.9366181  0.0040347  5189.15   <2e-16 ***
log(SCHOOL_COUNT)  0.4755516  0.0004701  1011.55   <2e-16 ***
log(RETAIL_COUNT)  0.1796905  0.0001856   968.12   <2e-16 ***
log(DIST)         -1.6929522  0.0004093 -4136.01   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 189463537  on 14471  degrees of freedom
Residual deviance:  15526121  on 14189  degrees of freedom
AIC: 15615824

Number of Fisher Scoring iterations: 6

Goodness-of-Fit

CalcRSquared <- function(observed, estimated){
  r  <- cor(observed,estimated)
  R2 <- r^2
  R2
}

Examine how the constraints hold for destinations

CalcRSquared(orcSIM$data$TRIPS, orcSIM$fitted.values)
[1] 0.4362208

Destination Constrained

decSIM <- glm(formula = TRIPS ~ 
                DESTIN_SZ + 
                log(SCHOOL_COUNT) + 
                log(DIST),
              family = poisson(link = "log"),
              data = inter_zonal_flow,
              na.action = na.exclude)
summary(decSIM)

Call:
glm(formula = TRIPS ~ DESTIN_SZ + log(SCHOOL_COUNT) + log(DIST), 
    family = poisson(link = "log"), data = inter_zonal_flow, 
    na.action = na.exclude)

Coefficients: (1 not defined because of singularities)
                    Estimate Std. Error   z value Pr(>|z|)    
(Intercept)       21.1707732  0.0043061  4916.502  < 2e-16 ***
DESTIN_SZAMSZ02    0.0371012  0.0044770     8.287  < 2e-16 ***
DESTIN_SZAMSZ03    0.1305469  0.0043909    29.731  < 2e-16 ***
DESTIN_SZAMSZ04   -1.0399621  0.0063788  -163.035  < 2e-16 ***
DESTIN_SZAMSZ05   -1.1200854  0.0064528  -173.581  < 2e-16 ***
DESTIN_SZAMSZ06   -1.1256714  0.0064401  -174.790  < 2e-16 ***
DESTIN_SZAMSZ07   -1.5880948  0.0097145  -163.477  < 2e-16 ***
DESTIN_SZAMSZ08   -0.5970367  0.0068843   -86.724  < 2e-16 ***
DESTIN_SZAMSZ09   -1.0674296  0.0065644  -162.608  < 2e-16 ***
DESTIN_SZAMSZ10   -0.0612203  0.0045919   -13.332  < 2e-16 ***
DESTIN_SZAMSZ11   -0.6955269  0.0086700   -80.222  < 2e-16 ***
DESTIN_SZAMSZ12    0.1620088  0.0050181    32.285  < 2e-16 ***
DESTIN_SZBDSZ01    0.9892232  0.0039751   248.856  < 2e-16 ***
DESTIN_SZBDSZ02    0.4017891  0.0052374    76.715  < 2e-16 ***
DESTIN_SZBDSZ03    0.3915377  0.0047764    81.974  < 2e-16 ***
DESTIN_SZBDSZ04    1.3768947  0.0038180   360.637  < 2e-16 ***
DESTIN_SZBDSZ05    0.9453454  0.0040922   231.014  < 2e-16 ***
DESTIN_SZBDSZ06    0.6929711  0.0046554   148.852  < 2e-16 ***
DESTIN_SZBDSZ07   -0.3688620  0.0096224   -38.333  < 2e-16 ***
DESTIN_SZBDSZ08   -0.9924523  0.0109418   -90.703  < 2e-16 ***
DESTIN_SZBKSZ01   -1.0093826  0.0067519  -149.497  < 2e-16 ***
DESTIN_SZBKSZ02   -0.1646950  0.0056050   -29.384  < 2e-16 ***
DESTIN_SZBKSZ03   -0.7702454  0.0060023  -128.324  < 2e-16 ***
DESTIN_SZBKSZ04   -0.2128866  0.0050053   -42.532  < 2e-16 ***
DESTIN_SZBKSZ05   -0.9222879  0.0066223  -139.271  < 2e-16 ***
DESTIN_SZBKSZ06   -1.0097287  0.0062224  -162.274  < 2e-16 ***
DESTIN_SZBKSZ07    0.0518689  0.0042400    12.233  < 2e-16 ***
DESTIN_SZBKSZ08   -1.2300650  0.0070344  -174.863  < 2e-16 ***
DESTIN_SZBKSZ09   -0.2258130  0.0049947   -45.211  < 2e-16 ***
DESTIN_SZBLSZ01   -0.8157866  0.0070499  -115.715  < 2e-16 ***
DESTIN_SZBLSZ02   -0.3027143  0.0065218   -46.416  < 2e-16 ***
DESTIN_SZBLSZ03    0.7958391  0.0074056   107.464  < 2e-16 ***
DESTIN_SZBLSZ04   -1.1098772  0.0131963   -84.105  < 2e-16 ***
DESTIN_SZBMSZ01   -0.1310007  0.0049367   -26.536  < 2e-16 ***
DESTIN_SZBMSZ02   -0.9571354  0.0049558  -193.135  < 2e-16 ***
DESTIN_SZBMSZ03   -1.2732655  0.0057277  -222.302  < 2e-16 ***
DESTIN_SZBMSZ04   -1.2035188  0.0051428  -234.019  < 2e-16 ***
DESTIN_SZBMSZ05   -1.1303172  0.0069498  -162.640  < 2e-16 ***
DESTIN_SZBMSZ06   -2.2950071  0.0131523  -174.495  < 2e-16 ***
DESTIN_SZBMSZ07   -0.3931446  0.0046619   -84.331  < 2e-16 ***
DESTIN_SZBMSZ08   -1.8285333  0.0065026  -281.200  < 2e-16 ***
DESTIN_SZBMSZ09   -3.3025704  0.0152460  -216.619  < 2e-16 ***
DESTIN_SZBMSZ10   -2.4668974  0.0089386  -275.984  < 2e-16 ***
DESTIN_SZBMSZ11   -2.1775261  0.0080886  -269.211  < 2e-16 ***
DESTIN_SZBMSZ12   -1.5533488  0.0080036  -194.082  < 2e-16 ***
DESTIN_SZBMSZ13   -0.6992349  0.0053943  -129.625  < 2e-16 ***
DESTIN_SZBMSZ14   -1.8682939  0.0077676  -240.524  < 2e-16 ***
DESTIN_SZBMSZ15   -1.6438723  0.0071068  -231.308  < 2e-16 ***
DESTIN_SZBMSZ16   -2.5319233  0.0113895  -222.304  < 2e-16 ***
DESTIN_SZBMSZ17   -2.3908644  0.0165777  -144.222  < 2e-16 ***
DESTIN_SZBPSZ01   -0.6933581  0.0056465  -122.794  < 2e-16 ***
DESTIN_SZBPSZ02   -1.5690150  0.0084981  -184.630  < 2e-16 ***
DESTIN_SZBPSZ03   -1.2386463  0.0081265  -152.421  < 2e-16 ***
DESTIN_SZBPSZ04   -0.4837251  0.0059697   -81.030  < 2e-16 ***
DESTIN_SZBPSZ05    0.4454953  0.0040664   109.555  < 2e-16 ***
DESTIN_SZBPSZ06   -0.6899975  0.0078508   -87.889  < 2e-16 ***
DESTIN_SZBPSZ07   -0.0337850  0.0080286    -4.208 2.58e-05 ***
DESTIN_SZBSSZ01    0.0103408  0.0049750     2.079  0.03766 *  
DESTIN_SZBSSZ02   -0.6528407  0.0056160  -116.247  < 2e-16 ***
DESTIN_SZBSSZ03    0.1882120  0.0041566    45.280  < 2e-16 ***
DESTIN_SZBTSZ01    0.3382397  0.0043637    77.513  < 2e-16 ***
DESTIN_SZBTSZ02   -0.1875880  0.0068276   -27.475  < 2e-16 ***
DESTIN_SZBTSZ03   -0.0023969  0.0054551    -0.439  0.66038    
DESTIN_SZBTSZ04   -1.4111336  0.0108345  -130.244  < 2e-16 ***
DESTIN_SZBTSZ05   -0.3020060  0.0069383   -43.528  < 2e-16 ***
DESTIN_SZBTSZ06   -0.9069295  0.0071064  -127.621  < 2e-16 ***
DESTIN_SZBTSZ07   -2.0566033  0.0110692  -185.795  < 2e-16 ***
DESTIN_SZBTSZ08   -1.6308254  0.0100369  -162.484  < 2e-16 ***
DESTIN_SZCBSZ01   -4.6894221  0.3162421   -14.829  < 2e-16 ***
DESTIN_SZCCSZ01   -0.3175428  0.0081545   -38.941  < 2e-16 ***
DESTIN_SZCHSZ01   -0.2225262  0.0097164   -22.902  < 2e-16 ***
DESTIN_SZCHSZ02   -0.0527951  0.0053337    -9.898  < 2e-16 ***
DESTIN_SZCHSZ03    2.5791911  0.0040210   641.427  < 2e-16 ***
DESTIN_SZCKSZ01    0.0380461  0.0049002     7.764 8.22e-15 ***
DESTIN_SZCKSZ02   -0.5355692  0.0056427   -94.913  < 2e-16 ***
DESTIN_SZCKSZ03    0.7279591  0.0039202   185.692  < 2e-16 ***
DESTIN_SZCKSZ04   -0.3927873  0.0064849   -60.569  < 2e-16 ***
DESTIN_SZCKSZ05   -0.2265622  0.0067908   -33.363  < 2e-16 ***
DESTIN_SZCKSZ06    0.3792036  0.0063560    59.661  < 2e-16 ***
DESTIN_SZCLSZ01    0.1985789  0.0047824    41.523  < 2e-16 ***
DESTIN_SZCLSZ02   -2.2113621  0.0133556  -165.576  < 2e-16 ***
DESTIN_SZCLSZ03   -0.9255834  0.0079113  -116.995  < 2e-16 ***
DESTIN_SZCLSZ04   -0.1778523  0.0047148   -37.722  < 2e-16 ***
DESTIN_SZCLSZ05   -1.0165236  0.0084225  -120.692  < 2e-16 ***
DESTIN_SZCLSZ06    0.0782223  0.0042366    18.464  < 2e-16 ***
DESTIN_SZCLSZ07   -0.6287187  0.0054055  -116.311  < 2e-16 ***
DESTIN_SZCLSZ08   -0.4117031  0.0060602   -67.936  < 2e-16 ***
DESTIN_SZCLSZ09    0.2912807  0.0064319    45.287  < 2e-16 ***
DESTIN_SZDTSZ02   -2.8442617  0.0348408   -81.636  < 2e-16 ***
DESTIN_SZDTSZ03   -1.2900158  0.0144157   -89.487  < 2e-16 ***
DESTIN_SZDTSZ13   -1.9250557  0.0161488  -119.207  < 2e-16 ***
DESTIN_SZGLSZ01   -0.3326449  0.0051942   -64.042  < 2e-16 ***
DESTIN_SZGLSZ02   -0.3423980  0.0050258   -68.128  < 2e-16 ***
DESTIN_SZGLSZ03    0.6399801  0.0040595   157.648  < 2e-16 ***
DESTIN_SZGLSZ04    0.4841066  0.0040594   119.257  < 2e-16 ***
DESTIN_SZGLSZ05    0.6374564  0.0040657   156.788  < 2e-16 ***
DESTIN_SZHGSZ01    0.4187988  0.0039341   106.453  < 2e-16 ***
DESTIN_SZHGSZ02   -0.4492928  0.0054169   -82.943  < 2e-16 ***
DESTIN_SZHGSZ03   -0.8660435  0.0064195  -134.908  < 2e-16 ***
DESTIN_SZHGSZ04   -0.1355849  0.0045847   -29.573  < 2e-16 ***
DESTIN_SZHGSZ05   -0.1702976  0.0048822   -34.882  < 2e-16 ***
DESTIN_SZHGSZ06   -0.6791409  0.0057858  -117.380  < 2e-16 ***
DESTIN_SZHGSZ07    0.1120254  0.0045478    24.633  < 2e-16 ***
DESTIN_SZHGSZ08   -0.1462153  0.0050534   -28.934  < 2e-16 ***
DESTIN_SZHGSZ09    0.1478227  0.0052771    28.012  < 2e-16 ***
DESTIN_SZHGSZ10   -3.1620450  0.0262185  -120.603  < 2e-16 ***
DESTIN_SZJESZ01   -0.0793984  0.0050217   -15.811  < 2e-16 ***
DESTIN_SZJESZ02   -0.6066484  0.0052905  -114.667  < 2e-16 ***
DESTIN_SZJESZ03   -0.7509810  0.0057895  -129.713  < 2e-16 ***
DESTIN_SZJESZ04   -0.5953199  0.0068411   -87.022  < 2e-16 ***
DESTIN_SZJESZ05   -1.4256269  0.0098351  -144.953  < 2e-16 ***
DESTIN_SZJESZ06    0.0751565  0.0040942    18.357  < 2e-16 ***
DESTIN_SZJESZ07   -1.3271024  0.0081680  -162.476  < 2e-16 ***
DESTIN_SZJESZ08   -0.5102034  0.0079051   -64.541  < 2e-16 ***
DESTIN_SZJESZ09   -0.3313742  0.0058246   -56.892  < 2e-16 ***
DESTIN_SZJESZ10    0.4692055  0.0069809    67.213  < 2e-16 ***
DESTIN_SZJESZ11    0.7112949  0.0065922   107.899  < 2e-16 ***
DESTIN_SZJWSZ01   -0.2912848  0.0066150   -44.034  < 2e-16 ***
DESTIN_SZJWSZ02   -0.1925559  0.0053346   -36.096  < 2e-16 ***
DESTIN_SZJWSZ03    0.8519463  0.0041075   207.410  < 2e-16 ***
DESTIN_SZJWSZ04    0.4754181  0.0042941   110.714  < 2e-16 ***
DESTIN_SZJWSZ05   -0.4796359  0.0061325   -78.212  < 2e-16 ***
DESTIN_SZJWSZ06    0.0170339  0.0054886     3.103  0.00191 ** 
DESTIN_SZJWSZ07   -2.1279563  0.0282640   -75.289  < 2e-16 ***
DESTIN_SZJWSZ08    0.7195812  0.0049261   146.074  < 2e-16 ***
DESTIN_SZJWSZ09    1.3717249  0.0035293   388.672  < 2e-16 ***
DESTIN_SZKLSZ01   -0.7073464  0.0055551  -127.333  < 2e-16 ***
DESTIN_SZKLSZ02   -0.9229516  0.0058853  -156.824  < 2e-16 ***
DESTIN_SZKLSZ03   -1.3012706  0.0066470  -195.769  < 2e-16 ***
DESTIN_SZKLSZ04   -1.8810416  0.0088292  -213.047  < 2e-16 ***
DESTIN_SZKLSZ05   -0.6937362  0.0085722   -80.928  < 2e-16 ***
DESTIN_SZKLSZ06   -3.0430960  0.0362084   -84.044  < 2e-16 ***
DESTIN_SZKLSZ07   -1.3333100  0.0067161  -198.523  < 2e-16 ***
DESTIN_SZKLSZ08   -0.7646952  0.0052081  -146.829  < 2e-16 ***
DESTIN_SZLKSZ01   -0.9648136  0.0205558   -46.936  < 2e-16 ***
DESTIN_SZMDSZ01   -1.0428993  0.0200264   -52.076  < 2e-16 ***
DESTIN_SZMDSZ02   -1.0088343  0.0112070   -90.019  < 2e-16 ***
DESTIN_SZMDSZ03   -2.7184894  0.0252253  -107.768  < 2e-16 ***
DESTIN_SZMPSZ01   -0.5908399  0.0078467   -75.298  < 2e-16 ***
DESTIN_SZMPSZ02   -0.5390898  0.0061456   -87.720  < 2e-16 ***
DESTIN_SZMPSZ03    0.2913883  0.0048981    59.490  < 2e-16 ***
DESTIN_SZMUSZ02   -2.9286103  0.0199668  -146.674  < 2e-16 ***
DESTIN_SZNTSZ01   -4.0762244  0.0447769   -91.034  < 2e-16 ***
DESTIN_SZNTSZ02   -2.2875955  0.0108975  -209.919  < 2e-16 ***
DESTIN_SZNTSZ03   -1.7916106  0.0076808  -233.260  < 2e-16 ***
DESTIN_SZNTSZ05   -3.5218868  0.0249610  -141.096  < 2e-16 ***
DESTIN_SZNTSZ06   -4.2102393  0.0428640   -98.223  < 2e-16 ***
DESTIN_SZNVSZ01   -0.5511901  0.0048421  -113.832  < 2e-16 ***
DESTIN_SZNVSZ02   -0.6842973  0.0054368  -125.864  < 2e-16 ***
DESTIN_SZNVSZ03   -0.5113844  0.0055405   -92.300  < 2e-16 ***
DESTIN_SZNVSZ04   -1.9609701  0.0108861  -180.136  < 2e-16 ***
DESTIN_SZNVSZ05   -1.6282127  0.0090731  -179.456  < 2e-16 ***
DESTIN_SZPGSZ01   -1.0593679  0.0158155   -66.983  < 2e-16 ***
DESTIN_SZPGSZ02   -0.5795806  0.0069647   -83.217  < 2e-16 ***
DESTIN_SZPGSZ03    0.3909755  0.0045088    86.713  < 2e-16 ***
DESTIN_SZPGSZ04    0.4558243  0.0046315    98.419  < 2e-16 ***
DESTIN_SZPGSZ05   -0.5125145  0.0079058   -64.828  < 2e-16 ***
DESTIN_SZPLSZ01   -0.1333415  0.0071760   -18.582  < 2e-16 ***
DESTIN_SZPLSZ02   -0.9709255  0.0133073   -72.962  < 2e-16 ***
DESTIN_SZPLSZ03   -0.6085644  0.0095955   -63.422  < 2e-16 ***
DESTIN_SZPLSZ04   -2.7425007  0.0093816  -292.328  < 2e-16 ***
DESTIN_SZPLSZ05   -0.8417587  0.0117010   -71.939  < 2e-16 ***
DESTIN_SZPNSZ01   -0.0121813  0.0060751    -2.005  0.04495 *  
DESTIN_SZPNSZ02    0.7631484  0.0064295   118.694  < 2e-16 ***
DESTIN_SZPNSZ03   -0.1043246  0.0076956   -13.556  < 2e-16 ***
DESTIN_SZPNSZ04    1.0351233  0.0075032   137.957  < 2e-16 ***
DESTIN_SZPNSZ05    0.2271643  0.0116266    19.538  < 2e-16 ***
DESTIN_SZPRSZ01   -0.6303237  0.0086378   -72.973  < 2e-16 ***
DESTIN_SZPRSZ02    0.2642641  0.0053008    49.854  < 2e-16 ***
DESTIN_SZPRSZ03    1.0170876  0.0039609   256.783  < 2e-16 ***
DESTIN_SZPRSZ04    0.2079891  0.0081112    25.642  < 2e-16 ***
DESTIN_SZPRSZ05    0.3417959  0.0049925    68.462  < 2e-16 ***
DESTIN_SZPRSZ06    0.5390524  0.0055203    97.650  < 2e-16 ***
DESTIN_SZPRSZ07   -1.9333913  0.0118415  -163.273  < 2e-16 ***
DESTIN_SZPRSZ08   -0.1910150  0.0065576   -29.129  < 2e-16 ***
DESTIN_SZQTSZ01   -1.3382706  0.0086422  -154.853  < 2e-16 ***
DESTIN_SZQTSZ02   -1.4965408  0.0074714  -200.304  < 2e-16 ***
DESTIN_SZQTSZ03   -1.3779365  0.0069203  -199.115  < 2e-16 ***
DESTIN_SZQTSZ04   -1.2773349  0.0068827  -185.586  < 2e-16 ***
DESTIN_SZQTSZ05   -1.3574169  0.0064940  -209.027  < 2e-16 ***
DESTIN_SZQTSZ06   -1.5263132  0.0067671  -225.549  < 2e-16 ***
DESTIN_SZQTSZ07   -1.9586230  0.0109634  -178.651  < 2e-16 ***
DESTIN_SZQTSZ08   -0.4303473  0.0051771   -83.125  < 2e-16 ***
DESTIN_SZQTSZ09   -0.8420154  0.0061124  -137.756  < 2e-16 ***
DESTIN_SZQTSZ10   -0.4557434  0.0055276   -82.448  < 2e-16 ***
DESTIN_SZQTSZ11   -0.3141765  0.0056414   -55.692  < 2e-16 ***
DESTIN_SZQTSZ12   -1.1034539  0.0082613  -133.569  < 2e-16 ***
DESTIN_SZQTSZ13   -0.2045638  0.0057646   -35.486  < 2e-16 ***
DESTIN_SZQTSZ14   -0.2763246  0.0066148   -41.774  < 2e-16 ***
DESTIN_SZQTSZ15    0.5654579  0.0078658    71.888  < 2e-16 ***
DESTIN_SZRCSZ01   -0.8221129  0.0071906  -114.331  < 2e-16 ***
DESTIN_SZRCSZ06   -1.5575544  0.0188859   -82.472  < 2e-16 ***
DESTIN_SZRVSZ01   -2.7796381  0.0162421  -171.138  < 2e-16 ***
DESTIN_SZRVSZ02   -2.8794393  0.0326171   -88.280  < 2e-16 ***
DESTIN_SZRVSZ03   -2.9115696  0.0136463  -213.359  < 2e-16 ***
DESTIN_SZRVSZ04   -2.5237482  0.0155011  -162.811  < 2e-16 ***
DESTIN_SZRVSZ05   -4.0058637  0.0262071  -152.854  < 2e-16 ***
DESTIN_SZSBSZ01   -1.2183497  0.0091460  -133.211  < 2e-16 ***
DESTIN_SZSBSZ02   -1.0903209  0.0077134  -141.354  < 2e-16 ***
DESTIN_SZSBSZ03    0.6055202  0.0043803   138.238  < 2e-16 ***
DESTIN_SZSBSZ04    0.3746039  0.0052892    70.824  < 2e-16 ***
DESTIN_SZSBSZ05   -1.0875343  0.0077022  -141.198  < 2e-16 ***
DESTIN_SZSBSZ06   -1.8270193  0.0221876   -82.344  < 2e-16 ***
DESTIN_SZSBSZ07   -0.5382117  0.0181906   -29.587  < 2e-16 ***
DESTIN_SZSBSZ08    1.1730685  0.0052334   224.150  < 2e-16 ***
DESTIN_SZSBSZ09    0.4129353  0.0048921    84.408  < 2e-16 ***
DESTIN_SZSESZ02    0.0934147  0.0049256    18.965  < 2e-16 ***
DESTIN_SZSESZ03    0.7697440  0.0038659   199.109  < 2e-16 ***
DESTIN_SZSESZ04   -0.4333259  0.0057461   -75.413  < 2e-16 ***
DESTIN_SZSESZ05   -0.1117549  0.0048635   -22.978  < 2e-16 ***
DESTIN_SZSESZ06   -0.3772855  0.0064222   -58.747  < 2e-16 ***
DESTIN_SZSESZ07   -2.8070689  0.0227290  -123.501  < 2e-16 ***
DESTIN_SZSGSZ01   -0.1312986  0.0058787   -22.334  < 2e-16 ***
DESTIN_SZSGSZ02    0.0097339  0.0052433     1.856  0.06339 .  
DESTIN_SZSGSZ03   -0.1985918  0.0048763   -40.726  < 2e-16 ***
DESTIN_SZSGSZ04   -0.1421981  0.0049567   -28.688  < 2e-16 ***
DESTIN_SZSGSZ05   -2.1015053  0.0100493  -209.120  < 2e-16 ***
DESTIN_SZSGSZ06    0.4177334  0.0039114   106.800  < 2e-16 ***
DESTIN_SZSGSZ07   -0.5572004  0.0053060  -105.014  < 2e-16 ***
DESTIN_SZSISZ01   -1.6866922  0.0257825   -65.420  < 2e-16 ***
DESTIN_SZSKSZ01   -0.0547600  0.0072702    -7.532 4.99e-14 ***
DESTIN_SZSKSZ02    1.2577275  0.0050573   248.697  < 2e-16 ***
DESTIN_SZSKSZ03    0.0986788  0.0059980    16.452  < 2e-16 ***
DESTIN_SZSKSZ04   -0.8889820  0.0140414   -63.311  < 2e-16 ***
DESTIN_SZSKSZ05   -0.2568016  0.0105209   -24.409  < 2e-16 ***
DESTIN_SZSLSZ01   -0.1895994  0.0083818   -22.620  < 2e-16 ***
DESTIN_SZSLSZ04   -0.3809817  0.0071348   -53.397  < 2e-16 ***
DESTIN_SZSRSZ01   -3.0146943  0.0130089  -231.740  < 2e-16 ***
DESTIN_SZTHSZ01   -3.1132404  0.0366860   -84.862  < 2e-16 ***
DESTIN_SZTHSZ03   -2.2150520  0.0251014   -88.244  < 2e-16 ***
DESTIN_SZTHSZ04   -2.7544085  0.0213728  -128.875  < 2e-16 ***
DESTIN_SZTHSZ06   -1.9539561  0.0153485  -127.306  < 2e-16 ***
DESTIN_SZTMSZ01    0.4897337  0.0055897    87.614  < 2e-16 ***
DESTIN_SZTMSZ02    1.9950293  0.0034804   573.219  < 2e-16 ***
DESTIN_SZTMSZ03    1.3339284  0.0039855   334.698  < 2e-16 ***
DESTIN_SZTMSZ04    1.6591506  0.0039214   423.105  < 2e-16 ***
DESTIN_SZTMSZ05    1.0962819  0.0056772   193.102  < 2e-16 ***
DESTIN_SZTNSZ01   -1.2211562  0.0071552  -170.666  < 2e-16 ***
DESTIN_SZTNSZ02   -2.3122987  0.0099124  -233.273  < 2e-16 ***
DESTIN_SZTNSZ03   -2.0866651  0.0117104  -178.189  < 2e-16 ***
DESTIN_SZTNSZ04   -1.0858305  0.0071883  -151.055  < 2e-16 ***
DESTIN_SZTPSZ01   -0.7136406  0.0059586  -119.767  < 2e-16 ***
DESTIN_SZTPSZ02    0.2420177  0.0038303    63.185  < 2e-16 ***
DESTIN_SZTPSZ03   -0.7530597  0.0056300  -133.758  < 2e-16 ***
DESTIN_SZTPSZ04   -1.7006370  0.0073620  -231.002  < 2e-16 ***
DESTIN_SZTPSZ05   -1.2310906  0.0058272  -211.267  < 2e-16 ***
DESTIN_SZTPSZ06   -0.8144830  0.0063418  -128.431  < 2e-16 ***
DESTIN_SZTPSZ07   -2.2661399  0.0116719  -194.154  < 2e-16 ***
DESTIN_SZTPSZ08   -1.6885660  0.0091067  -185.419  < 2e-16 ***
DESTIN_SZTPSZ09   -0.5642441  0.0067796   -83.227  < 2e-16 ***
DESTIN_SZTPSZ10   -1.5082863  0.0088455  -170.514  < 2e-16 ***
DESTIN_SZTPSZ11   -0.5583809  0.0053491  -104.388  < 2e-16 ***
DESTIN_SZTPSZ12   -0.9538104  0.0064014  -149.001  < 2e-16 ***
DESTIN_SZTSSZ01   -1.4451145  0.0208619   -69.270  < 2e-16 ***
DESTIN_SZTSSZ02   -0.4752373  0.0133278   -35.658  < 2e-16 ***
DESTIN_SZTSSZ03    0.6502289  0.0076057    85.492  < 2e-16 ***
DESTIN_SZTSSZ04    0.2845382  0.0079498    35.792  < 2e-16 ***
DESTIN_SZTSSZ05    1.1877409  0.0073930   160.657  < 2e-16 ***
DESTIN_SZTSSZ06    1.7332590  0.0140776   123.122  < 2e-16 ***
DESTIN_SZWCSZ01    2.6002592  0.0046409   560.287  < 2e-16 ***
DESTIN_SZWCSZ02   -0.6539688  0.0123673   -52.879  < 2e-16 ***
DESTIN_SZWCSZ03   -1.8564952  0.0325152   -57.096  < 2e-16 ***
DESTIN_SZWDSZ01    1.4131757  0.0035171   401.798  < 2e-16 ***
DESTIN_SZWDSZ02   -0.4605303  0.0059449   -77.467  < 2e-16 ***
DESTIN_SZWDSZ03    0.6847531  0.0045055   151.982  < 2e-16 ***
DESTIN_SZWDSZ04    0.0836263  0.0067610    12.369  < 2e-16 ***
DESTIN_SZWDSZ05    0.0772911  0.0066889    11.555  < 2e-16 ***
DESTIN_SZWDSZ06    0.4519395  0.0045580    99.153  < 2e-16 ***
DESTIN_SZWDSZ07   -0.4468713  0.0063890   -69.944  < 2e-16 ***
DESTIN_SZWDSZ08   -0.0566422  0.0062549    -9.056  < 2e-16 ***
DESTIN_SZWDSZ09    0.5814453  0.0046563   124.872  < 2e-16 ***
DESTIN_SZYSSZ01    0.9988417  0.0038893   256.819  < 2e-16 ***
DESTIN_SZYSSZ02    0.3934862  0.0051025    77.117  < 2e-16 ***
DESTIN_SZYSSZ03   -0.0879967  0.0061744   -14.252  < 2e-16 ***
DESTIN_SZYSSZ04   -0.0041863  0.0052771    -0.793  0.42761    
DESTIN_SZYSSZ05   -0.9576475  0.0108533   -88.236  < 2e-16 ***
DESTIN_SZYSSZ06   -1.3716686  0.0106170  -129.195  < 2e-16 ***
DESTIN_SZYSSZ07   -0.8517973  0.0142269   -59.872  < 2e-16 ***
DESTIN_SZYSSZ08    1.0775536  0.0040061   268.980  < 2e-16 ***
DESTIN_SZYSSZ09    0.3694023  0.0042180    87.577  < 2e-16 ***
log(SCHOOL_COUNT)         NA         NA        NA       NA    
log(DIST)         -1.7525619  0.0004141 -4231.928  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 47094011  on 14470  degrees of freedom
Residual deviance: 18757606  on 14190  degrees of freedom
AIC: 18847306

Number of Fisher Scoring iterations: 7
CalcRSquared(decSIM$data$TRIPS, decSIM$fitted.values)
[1] 0.3735052

Doubly Constrained

dbcSIM <- glm(formula = TRIPS ~
                ORIGIN_SZ +
                DESTIN_SZ +
                log(DIST),
              family = poisson(link = "log"),
              data = inter_zonal_flow,
              na.action = na.exclude)
dbcSIM

Call:  glm(formula = TRIPS ~ ORIGIN_SZ + DESTIN_SZ + log(DIST), family = poisson(link = "log"), 
    data = inter_zonal_flow, na.action = na.exclude)

Coefficients:
    (Intercept)  ORIGIN_SZAMSZ02  ORIGIN_SZAMSZ03  ORIGIN_SZAMSZ04  
     21.8312374        0.5263502        0.3139982       -0.2146257  
ORIGIN_SZAMSZ05  ORIGIN_SZAMSZ06  ORIGIN_SZAMSZ07  ORIGIN_SZAMSZ08  
     -0.1890446        0.1539201       -0.9826565       -0.4488417  
ORIGIN_SZAMSZ09  ORIGIN_SZAMSZ10  ORIGIN_SZAMSZ11  ORIGIN_SZAMSZ12  
      0.0713474        0.4313742       -1.4712226       -1.7250733  
ORIGIN_SZBDSZ01  ORIGIN_SZBDSZ02  ORIGIN_SZBDSZ03  ORIGIN_SZBDSZ04  
      0.8810576        0.1100240        0.3606166        1.4624347  
ORIGIN_SZBDSZ05  ORIGIN_SZBDSZ06  ORIGIN_SZBDSZ07  ORIGIN_SZBDSZ08  
      0.6207557        0.6712973       -1.2338669       -1.0444562  
ORIGIN_SZBKSZ01  ORIGIN_SZBKSZ02  ORIGIN_SZBKSZ03  ORIGIN_SZBKSZ04  
     -0.2838426        0.5550522        0.7396640       -0.2242451  
ORIGIN_SZBKSZ05  ORIGIN_SZBKSZ06  ORIGIN_SZBKSZ07  ORIGIN_SZBKSZ08  
     -0.2371614       -0.1413812        0.7089989       -0.0907065  
ORIGIN_SZBKSZ09  ORIGIN_SZBLSZ01  ORIGIN_SZBLSZ02  ORIGIN_SZBLSZ03  
     -0.1775146       -2.3684539       -2.8078475       -3.3122763  
ORIGIN_SZBLSZ04  ORIGIN_SZBMSZ01  ORIGIN_SZBMSZ02  ORIGIN_SZBMSZ03  
     -2.6770542        0.0618035       -1.3535767       -0.7569095  
ORIGIN_SZBMSZ04  ORIGIN_SZBMSZ05  ORIGIN_SZBMSZ06  ORIGIN_SZBMSZ07  
     -0.2949304       -2.6131992       -3.0315024       -0.6962524  
ORIGIN_SZBMSZ08  ORIGIN_SZBMSZ09  ORIGIN_SZBMSZ10  ORIGIN_SZBMSZ11  
     -0.9310730       -1.2911253       -1.6687004       -1.1152794  
ORIGIN_SZBMSZ12  ORIGIN_SZBMSZ13  ORIGIN_SZBMSZ14  ORIGIN_SZBMSZ15  
     -1.5323954       -0.6267376       -1.0475467       -0.5049444  
ORIGIN_SZBMSZ16  ORIGIN_SZBMSZ17  ORIGIN_SZBPSZ01  ORIGIN_SZBPSZ02  
     -1.5282897       -1.5722349        0.5814175        0.0875442  
ORIGIN_SZBPSZ03  ORIGIN_SZBPSZ04  ORIGIN_SZBPSZ05  ORIGIN_SZBPSZ06  
      0.3358227        0.6507586        0.9502124       -1.0480314  
ORIGIN_SZBPSZ07  ORIGIN_SZBSSZ01  ORIGIN_SZBSSZ02  ORIGIN_SZBSSZ03  
     -0.5467931        0.2998334        0.2841036       -0.2331505  
ORIGIN_SZBTSZ01  ORIGIN_SZBTSZ02  ORIGIN_SZBTSZ03  ORIGIN_SZBTSZ04  
      0.0987284       -0.6261229       -0.4326963       -1.4998668  
ORIGIN_SZBTSZ05  ORIGIN_SZBTSZ06  ORIGIN_SZBTSZ07  ORIGIN_SZBTSZ08  
     -0.9564768       -1.2853131       -2.3870991       -1.3715855  
ORIGIN_SZCBSZ01  ORIGIN_SZCCSZ01  ORIGIN_SZCHSZ01  ORIGIN_SZCHSZ02  
     -3.5940232       -0.7008220       -0.9109524       -0.8566547  
ORIGIN_SZCHSZ03  ORIGIN_SZCKSZ01  ORIGIN_SZCKSZ02  ORIGIN_SZCKSZ03  
      1.1153731        0.3001815        0.7185711        1.1389824  
ORIGIN_SZCKSZ04  ORIGIN_SZCKSZ05  ORIGIN_SZCKSZ06  ORIGIN_SZCLSZ01  
      1.6281772        0.8338470        0.6528993       -0.7174758  
ORIGIN_SZCLSZ02  ORIGIN_SZCLSZ03  ORIGIN_SZCLSZ04  ORIGIN_SZCLSZ05  
     -1.7513100       -1.0362873        0.6160017       -2.1005122  
ORIGIN_SZCLSZ06  ORIGIN_SZCLSZ07  ORIGIN_SZCLSZ08  ORIGIN_SZCLSZ09  
      0.7252108       -0.5343482       -0.2153408       -1.8019961  
ORIGIN_SZDTSZ02  ORIGIN_SZDTSZ03  ORIGIN_SZDTSZ13  ORIGIN_SZGLSZ01  
     -3.9057711       -3.4152419       -3.0183438       -1.7812384  
ORIGIN_SZGLSZ02  ORIGIN_SZGLSZ03  ORIGIN_SZGLSZ04  ORIGIN_SZGLSZ05  
     -0.1074991       -0.2461106        0.8657186        0.5871393  
ORIGIN_SZHGSZ01  ORIGIN_SZHGSZ02  ORIGIN_SZHGSZ03  ORIGIN_SZHGSZ04  
      0.3543819        0.4218178        0.2411309        0.8180622  
ORIGIN_SZHGSZ05  ORIGIN_SZHGSZ06  ORIGIN_SZHGSZ07  ORIGIN_SZHGSZ08  
      1.2173687       -0.1826300        0.3172839       -0.1151369  
ORIGIN_SZHGSZ09  ORIGIN_SZHGSZ10  ORIGIN_SZJESZ01  ORIGIN_SZJESZ02  
     -1.2873441       -3.3783178        0.4859234        0.1766088  
ORIGIN_SZJESZ03  ORIGIN_SZJESZ04  ORIGIN_SZJESZ05  ORIGIN_SZJESZ06  
     -0.2177441       -1.5532182       -2.3332926        0.3007382  
ORIGIN_SZJESZ07  ORIGIN_SZJESZ08  ORIGIN_SZJESZ09  ORIGIN_SZJESZ10  
     -1.9687994       -1.3032070        0.5762635       -1.4423113  
ORIGIN_SZJESZ11  ORIGIN_SZJWSZ01  ORIGIN_SZJWSZ02  ORIGIN_SZJWSZ03  
     -1.9720897        0.3808627        0.7963999        1.5429636  
ORIGIN_SZJWSZ04  ORIGIN_SZJWSZ05  ORIGIN_SZJWSZ06  ORIGIN_SZJWSZ07  
      0.6410760       -2.1571049       -1.5174532       -2.7089963  
ORIGIN_SZJWSZ08  ORIGIN_SZJWSZ09  ORIGIN_SZKLSZ01  ORIGIN_SZKLSZ02  
      1.5343415        1.8837410        0.1081286       -0.8844695  
ORIGIN_SZKLSZ03  ORIGIN_SZKLSZ04  ORIGIN_SZKLSZ05  ORIGIN_SZKLSZ06  
     -0.6872640       -2.2090319       -1.1728726       -6.1162315  
ORIGIN_SZKLSZ07  ORIGIN_SZKLSZ08  ORIGIN_SZLKSZ01  ORIGIN_SZMDSZ01  
     -1.4082749       -1.7781551       -2.0531568       -0.8825639  
ORIGIN_SZMDSZ02  ORIGIN_SZMDSZ03  ORIGIN_SZMPSZ01  ORIGIN_SZMPSZ02  
     -0.6219993       -2.0840156       -0.9659093       -1.0411153  
ORIGIN_SZMPSZ03  ORIGIN_SZMUSZ02  ORIGIN_SZNTSZ01  ORIGIN_SZNTSZ02  
      0.0001659       -3.7599031       -3.0388366       -3.4230640  
ORIGIN_SZNTSZ03  ORIGIN_SZNTSZ05  ORIGIN_SZNTSZ06  ORIGIN_SZNVSZ01  
     -0.9094796       -4.0861681       -3.9497128        0.3235636  
ORIGIN_SZNVSZ02  ORIGIN_SZNVSZ03  ORIGIN_SZNVSZ04  ORIGIN_SZNVSZ05  
     -0.6946748       -1.0540196       -0.9897977       -2.2578432  
ORIGIN_SZPGSZ01  ORIGIN_SZPGSZ02  ORIGIN_SZPGSZ03  ORIGIN_SZPGSZ04  
      0.2399827       -0.3352342        0.9515148        1.3998952  
ORIGIN_SZPGSZ05  ORIGIN_SZPLSZ01  ORIGIN_SZPLSZ02  ORIGIN_SZPLSZ03  
      0.4451629       -0.9705918       -1.0670151       -2.1229124  
ORIGIN_SZPLSZ04  ORIGIN_SZPLSZ05  ORIGIN_SZPNSZ01  ORIGIN_SZPNSZ02  
     -3.0911932       -2.1705708        0.9052637       -0.1720425  
ORIGIN_SZPNSZ03  ORIGIN_SZPNSZ04  ORIGIN_SZPNSZ05  ORIGIN_SZPRSZ01  
     -2.3973459       -3.4483689       -2.0588530       -0.6399015  
ORIGIN_SZPRSZ02  ORIGIN_SZPRSZ03  ORIGIN_SZPRSZ04  ORIGIN_SZPRSZ05  
      0.8122270        0.3990960       -0.8485348        0.8008791  
ORIGIN_SZPRSZ06  ORIGIN_SZPRSZ07  ORIGIN_SZPRSZ08  ORIGIN_SZQTSZ01  
     -1.4498806       -3.2025045       -0.5862269       -0.1859270  
ORIGIN_SZQTSZ02  ORIGIN_SZQTSZ03  ORIGIN_SZQTSZ04  ORIGIN_SZQTSZ05  
     -0.8715122       -0.1259816       -1.4620032       -0.6675643  
ORIGIN_SZQTSZ06  ORIGIN_SZQTSZ07  ORIGIN_SZQTSZ08  ORIGIN_SZQTSZ09  
     -0.8190026       -1.5189403       -0.4976238       -0.9006162  
ORIGIN_SZQTSZ10  ORIGIN_SZQTSZ11  ORIGIN_SZQTSZ12  ORIGIN_SZQTSZ13  
     -0.6690184       -2.5203437       -3.0461675       -0.7501068  
ORIGIN_SZQTSZ14  ORIGIN_SZQTSZ15  ORIGIN_SZRCSZ01  ORIGIN_SZRCSZ06  
     -1.9321849       -0.9576828       -1.8167951       -0.5560563  
ORIGIN_SZRVSZ01  ORIGIN_SZRVSZ02  ORIGIN_SZRVSZ03  ORIGIN_SZRVSZ04  
     -2.8862570       -3.1555662       -2.9836089       -3.5520422  
ORIGIN_SZRVSZ05  ORIGIN_SZSBSZ01  ORIGIN_SZSBSZ02  ORIGIN_SZSBSZ03  
     -2.5866584        0.2867444       -0.9012334        0.8311038  
ORIGIN_SZSBSZ04  ORIGIN_SZSBSZ05  ORIGIN_SZSBSZ06  ORIGIN_SZSBSZ07  
      0.4044170       -0.2661845       -0.9023075        0.0505870  
ORIGIN_SZSBSZ08  ORIGIN_SZSBSZ09  ORIGIN_SZSESZ02  ORIGIN_SZSESZ03  
     -1.1158011       -0.9682835        1.1452735        1.2815277  
ORIGIN_SZSESZ04  ORIGIN_SZSESZ05  ORIGIN_SZSESZ06  ORIGIN_SZSESZ07  
      0.8085857       -0.2329413        1.0576879       -2.3165908  
ORIGIN_SZSGSZ01  ORIGIN_SZSGSZ02  ORIGIN_SZSGSZ03  ORIGIN_SZSGSZ04  
     -0.6606350       -1.3638984        0.1152591        0.2954067  
ORIGIN_SZSGSZ05  ORIGIN_SZSGSZ06  ORIGIN_SZSGSZ07  ORIGIN_SZSKSZ01  
     -2.0792678        0.4563227       -0.8955254       -0.3184402  
ORIGIN_SZSKSZ02  ORIGIN_SZSKSZ03  ORIGIN_SZSKSZ04  ORIGIN_SZSKSZ05  
      1.1160484       -0.2566692       -1.5781827       -0.2724361  
ORIGIN_SZSLSZ01  ORIGIN_SZSLSZ04  ORIGIN_SZSRSZ01  ORIGIN_SZTHSZ01  
     -2.4458625       -0.0987076       -2.2584977       -2.5878524  
ORIGIN_SZTHSZ03  ORIGIN_SZTHSZ04  ORIGIN_SZTHSZ06  ORIGIN_SZTMSZ01  
     -0.8101746       -2.4186655       -1.7080541       -0.2193476  
ORIGIN_SZTMSZ02  ORIGIN_SZTMSZ03  ORIGIN_SZTMSZ04  ORIGIN_SZTMSZ05  
      1.7772464        1.0051343        0.1642370       -1.2878706  
ORIGIN_SZTNSZ01  ORIGIN_SZTNSZ02  ORIGIN_SZTNSZ03  ORIGIN_SZTNSZ04  
     -1.7163504       -1.6508988       -2.1545577       -0.3949120  
ORIGIN_SZTPSZ01  ORIGIN_SZTPSZ02  ORIGIN_SZTPSZ03  ORIGIN_SZTPSZ04  
     -0.8058100        0.5369060       -0.7779333       -0.8153581  
ORIGIN_SZTPSZ05  ORIGIN_SZTPSZ06  ORIGIN_SZTPSZ07  ORIGIN_SZTPSZ08  
     -0.5073676        0.0847301       -0.5839519       -1.0577941  
ORIGIN_SZTPSZ09  ORIGIN_SZTPSZ10  ORIGIN_SZTPSZ11  ORIGIN_SZTPSZ12  
     -0.9067707       -1.1362091       -0.2374621       -0.8028874  
ORIGIN_SZTSSZ01  ORIGIN_SZTSSZ02  ORIGIN_SZTSSZ03  ORIGIN_SZTSSZ04  
     -2.7809271        0.0425804        0.1142369       -0.6186261  
ORIGIN_SZTSSZ05  ORIGIN_SZTSSZ06  ORIGIN_SZWCSZ01  ORIGIN_SZWCSZ02  
     -1.0846732        0.3980173        1.3545143       -2.9863278  
ORIGIN_SZWCSZ03  ORIGIN_SZWDSZ01  ORIGIN_SZWDSZ02  ORIGIN_SZWDSZ03  
     -5.0504916        1.5238429        0.2832576        1.3702524  
ORIGIN_SZWDSZ04  ORIGIN_SZWDSZ05  ORIGIN_SZWDSZ06  ORIGIN_SZWDSZ07  
      1.0248225        0.2356778        0.3146925       -1.4971897  
ORIGIN_SZWDSZ08  ORIGIN_SZWDSZ09  ORIGIN_SZYSSZ01  ORIGIN_SZYSSZ02  
     -0.8894079        1.4437633       -0.2519398        0.8726785  
ORIGIN_SZYSSZ03  ORIGIN_SZYSSZ04  ORIGIN_SZYSSZ05  ORIGIN_SZYSSZ06  
      1.7868139        0.8418040        0.4292096       -0.7459961  
ORIGIN_SZYSSZ07  ORIGIN_SZYSSZ08  ORIGIN_SZYSSZ09  DESTIN_SZAMSZ02  
     -0.8422281        0.1829428        1.1159712        0.0694567  
DESTIN_SZAMSZ03  DESTIN_SZAMSZ04  DESTIN_SZAMSZ05  DESTIN_SZAMSZ06  
      0.0760100       -1.1306391       -1.0751133       -0.9624298  
DESTIN_SZAMSZ07  DESTIN_SZAMSZ08  DESTIN_SZAMSZ09  DESTIN_SZAMSZ10  
     -1.5060319       -0.4813202       -1.0220675        0.1235142  
DESTIN_SZAMSZ11  DESTIN_SZAMSZ12  DESTIN_SZBDSZ01  DESTIN_SZBDSZ02  
     -0.8917993        0.0195208        0.9736349       -0.1969470  
DESTIN_SZBDSZ03  DESTIN_SZBDSZ04  DESTIN_SZBDSZ05  DESTIN_SZBDSZ06  
      0.1266471        1.1608485        0.9293840        0.4090567  
DESTIN_SZBDSZ07  DESTIN_SZBDSZ08  DESTIN_SZBKSZ01  DESTIN_SZBKSZ02  
     -0.8171478       -1.5895287       -1.3793311       -0.5253670  
DESTIN_SZBKSZ03  DESTIN_SZBKSZ04  DESTIN_SZBKSZ05  DESTIN_SZBKSZ06  
     -1.0095362       -0.5662858       -0.9406607       -1.3129276  
DESTIN_SZBKSZ07  DESTIN_SZBKSZ08  DESTIN_SZBKSZ09  DESTIN_SZBLSZ01  
      0.0120605       -1.3658471       -0.1771310       -0.8175223  
DESTIN_SZBLSZ02  DESTIN_SZBLSZ03  DESTIN_SZBLSZ04  DESTIN_SZBMSZ01  
      0.1631280        1.2598494       -0.5642975        0.6921844  
DESTIN_SZBMSZ02  DESTIN_SZBMSZ03  DESTIN_SZBMSZ04  DESTIN_SZBMSZ05  
     -0.1209392       -0.2373881       -0.0407117       -0.2363309  
DESTIN_SZBMSZ06  DESTIN_SZBMSZ07  DESTIN_SZBMSZ08  DESTIN_SZBMSZ09  
     -1.1930710        0.4625103       -0.8604731       -2.1290239  
DESTIN_SZBMSZ10  DESTIN_SZBMSZ11  DESTIN_SZBMSZ12  DESTIN_SZBMSZ13  
     -1.4617153       -1.3234050       -0.8399230        0.1366529  
DESTIN_SZBMSZ14  DESTIN_SZBMSZ15  DESTIN_SZBMSZ16  DESTIN_SZBMSZ17  
     -1.0491968       -0.6726684       -1.4011734       -1.5682752  
DESTIN_SZBPSZ01  DESTIN_SZBPSZ02  DESTIN_SZBPSZ03  DESTIN_SZBPSZ04  
     -1.1120017       -2.0833466       -1.6937265       -0.7964999  
DESTIN_SZBPSZ05  DESTIN_SZBPSZ06  DESTIN_SZBPSZ07  DESTIN_SZBSSZ01  
      0.2109118       -1.1808365       -0.2077428        0.3164175  
DESTIN_SZBSSZ02  DESTIN_SZBSSZ03  DESTIN_SZBTSZ01  DESTIN_SZBTSZ02  
     -0.4852688        0.4130432        0.6215095       -0.0145076  
DESTIN_SZBTSZ03  DESTIN_SZBTSZ04  DESTIN_SZBTSZ05  DESTIN_SZBTSZ06  
      0.4919981       -0.6957555        0.3329814       -0.1333295  
DESTIN_SZBTSZ07  DESTIN_SZBTSZ08  DESTIN_SZCBSZ01  DESTIN_SZCCSZ01  
     -1.4449581       -0.7079056       -5.7344725       -0.0009541  
DESTIN_SZCHSZ01  DESTIN_SZCHSZ02  DESTIN_SZCHSZ03  DESTIN_SZCKSZ01  
     -0.2083016        0.5369606        2.5530638       -0.5725975  
DESTIN_SZCKSZ02  DESTIN_SZCKSZ03  DESTIN_SZCKSZ04  DESTIN_SZCKSZ05  
     -1.1181852        0.1156680       -0.8647725       -1.1641791  
DESTIN_SZCKSZ06  DESTIN_SZCLSZ01  DESTIN_SZCLSZ02  DESTIN_SZCLSZ03  
     -0.4397612        0.1930552       -2.0436501       -0.9338571  
DESTIN_SZCLSZ04  DESTIN_SZCLSZ05  DESTIN_SZCLSZ06  DESTIN_SZCLSZ07  
      0.0532041       -1.0782781        0.4068171       -0.3579507  
DESTIN_SZCLSZ08  DESTIN_SZCLSZ09  DESTIN_SZDTSZ02  DESTIN_SZDTSZ03  
     -0.2487993        0.1611080       -1.7308348       -0.5994253  
DESTIN_SZDTSZ13  DESTIN_SZGLSZ01  DESTIN_SZGLSZ02  DESTIN_SZGLSZ03  
     -1.3685031       -0.0910001       -0.0692224        0.6493421  
DESTIN_SZGLSZ04  DESTIN_SZGLSZ05  DESTIN_SZHGSZ01  DESTIN_SZHGSZ02  
      0.9327947        0.8161728        0.0658625       -0.8134329  
DESTIN_SZHGSZ03  DESTIN_SZHGSZ04  DESTIN_SZHGSZ05  DESTIN_SZHGSZ06  
     -1.3546132       -0.4500588       -0.5026431       -0.8673686  
DESTIN_SZHGSZ07  DESTIN_SZHGSZ08  DESTIN_SZHGSZ09  DESTIN_SZHGSZ10  
      0.0560490       -0.0443189       -0.0126355       -3.5821793  
DESTIN_SZJESZ01  DESTIN_SZJESZ02  DESTIN_SZJESZ03  DESTIN_SZJESZ04  
     -0.3704281       -0.7369159       -0.8985484       -1.0511995  
DESTIN_SZJESZ05  DESTIN_SZJESZ06  DESTIN_SZJESZ07  DESTIN_SZJESZ08  
     -1.5324974        0.3105267       -1.3234483       -0.6559742  
DESTIN_SZJESZ09  DESTIN_SZJESZ10  DESTIN_SZJESZ11  DESTIN_SZJWSZ01  
      0.2663752        0.8529026        0.5559641       -0.9790971  
DESTIN_SZJWSZ02  DESTIN_SZJWSZ03  DESTIN_SZJWSZ04  DESTIN_SZJWSZ05  
     -0.8746590        0.5689062        0.4520963       -1.0249671  
DESTIN_SZJWSZ06  DESTIN_SZJWSZ07  DESTIN_SZJWSZ08  DESTIN_SZJWSZ09  
     -0.7451483       -2.8453099       -0.3372309        1.0505330  
DESTIN_SZKLSZ01  DESTIN_SZKLSZ02  DESTIN_SZKLSZ03  DESTIN_SZKLSZ04  
     -0.2334836       -0.5416148       -0.8026495       -1.2918594  
DESTIN_SZKLSZ05  DESTIN_SZKLSZ06  DESTIN_SZKLSZ07  DESTIN_SZKLSZ08  
     -0.4069101       -2.5333101       -0.6623343       -0.1408205  
DESTIN_SZLKSZ01  DESTIN_SZMDSZ01  DESTIN_SZMDSZ02  DESTIN_SZMDSZ03  
     -1.2639235       -1.5655800       -0.9767682       -3.3328109  
DESTIN_SZMPSZ01  DESTIN_SZMPSZ02  DESTIN_SZMPSZ03  DESTIN_SZMUSZ02  
     -0.4552859       -0.5386560        0.4952000       -1.4434175  
DESTIN_SZNTSZ01  DESTIN_SZNTSZ02  DESTIN_SZNTSZ03  DESTIN_SZNTSZ05  
     -2.9194067       -1.3780179       -0.5044699       -2.0017134  
DESTIN_SZNTSZ06  DESTIN_SZNVSZ01  DESTIN_SZNVSZ02  DESTIN_SZNVSZ03  
     -3.8120537       -0.1071506       -0.0274710        0.1076352  
DESTIN_SZNVSZ04  DESTIN_SZNVSZ05  DESTIN_SZPGSZ01  DESTIN_SZPGSZ02  
     -1.2087250       -1.0058290       -1.2029931       -1.2878671  
DESTIN_SZPGSZ03  DESTIN_SZPGSZ04  DESTIN_SZPGSZ05  DESTIN_SZPLSZ01  
     -0.1520894       -0.1985959       -1.5290983       -0.3567934  
DESTIN_SZPLSZ02  DESTIN_SZPLSZ03  DESTIN_SZPLSZ04  DESTIN_SZPLSZ05  
     -1.7114351       -0.3241427       -1.7117196       -0.5086379  
DESTIN_SZPNSZ01  DESTIN_SZPNSZ02  DESTIN_SZPNSZ03  DESTIN_SZPNSZ04  
      0.2026781        0.8313754       -0.4041254        1.5814539  
DESTIN_SZPNSZ05  DESTIN_SZPRSZ01  DESTIN_SZPRSZ02  DESTIN_SZPRSZ03  
      1.1823430       -1.1057553        0.0895099        0.6921925  
DESTIN_SZPRSZ04  DESTIN_SZPRSZ05  DESTIN_SZPRSZ06  DESTIN_SZPRSZ07  
     -0.2848336        0.1744480        0.4279206       -1.5123108  
DESTIN_SZPRSZ08  DESTIN_SZQTSZ01  DESTIN_SZQTSZ02  DESTIN_SZQTSZ03  
     -0.5650226       -0.5952360       -0.7728170       -0.5066812  
DESTIN_SZQTSZ04  DESTIN_SZQTSZ05  DESTIN_SZQTSZ06  DESTIN_SZQTSZ07  
     -0.6398414       -0.4354527       -0.6597391       -0.9392696  
DESTIN_SZQTSZ08  DESTIN_SZQTSZ09  DESTIN_SZQTSZ10  DESTIN_SZQTSZ11  
      0.4617774       -0.3174497        0.1993449        0.2551535  
DESTIN_SZQTSZ12  DESTIN_SZQTSZ13  DESTIN_SZQTSZ14  DESTIN_SZQTSZ15  
     -0.1662603        0.5500978        0.5364435        1.3611043  
DESTIN_SZRCSZ01  DESTIN_SZRCSZ06  DESTIN_SZRVSZ01  DESTIN_SZRVSZ02  
     -0.1034049       -1.0633902       -1.5486221       -2.4092611  
DESTIN_SZRVSZ03  DESTIN_SZRVSZ04  DESTIN_SZRVSZ05  DESTIN_SZSBSZ01  
     -1.5172079       -1.1663615       -2.2404292       -1.3783780  
DESTIN_SZSBSZ02  DESTIN_SZSBSZ03  DESTIN_SZSBSZ04  DESTIN_SZSBSZ05  
     -1.4445213        0.5149906        0.2389086       -1.2737442  
DESTIN_SZSBSZ06  DESTIN_SZSBSZ07  DESTIN_SZSBSZ08  DESTIN_SZSBSZ09  
     -1.8683520       -0.5993154        0.8156302        0.0900611  
DESTIN_SZSESZ02  DESTIN_SZSESZ03  DESTIN_SZSESZ04  DESTIN_SZSESZ05  
     -0.6397704        0.1714103       -1.0596175       -0.8071891  
DESTIN_SZSESZ06  DESTIN_SZSESZ07  DESTIN_SZSGSZ01  DESTIN_SZSGSZ02  
     -0.5580934       -3.1448863       -0.1795225       -0.2986570  
DESTIN_SZSGSZ03  DESTIN_SZSGSZ04  DESTIN_SZSGSZ05  DESTIN_SZSGSZ06  
     -0.4074671       -0.1505164       -1.9908372        0.6715268  
DESTIN_SZSGSZ07  DESTIN_SZSISZ01  DESTIN_SZSKSZ01  DESTIN_SZSKSZ02  
     -0.4494757       -0.5517983       -0.4749154        0.9400302  
DESTIN_SZSKSZ03  DESTIN_SZSKSZ04  DESTIN_SZSKSZ05  DESTIN_SZSLSZ01  
     -0.2800377       -1.2570212       -0.2600474       -0.7775604  
DESTIN_SZSLSZ04  DESTIN_SZSRSZ01  DESTIN_SZTHSZ01  DESTIN_SZTHSZ03  
     -0.8586515       -1.1370887       -4.3259988       -2.6632914  
DESTIN_SZTHSZ04  DESTIN_SZTHSZ06  DESTIN_SZTMSZ01  DESTIN_SZTMSZ02  
     -3.1000906       -2.5952642       -0.2092828        1.8238139  
DESTIN_SZTMSZ03  DESTIN_SZTMSZ04  DESTIN_SZTMSZ05  DESTIN_SZTNSZ01  
      0.8518259        1.0222812        0.6323777       -0.3336078  
DESTIN_SZTNSZ02  DESTIN_SZTNSZ03  DESTIN_SZTNSZ04  DESTIN_SZTPSZ01  
     -1.0820469       -1.4186505       -0.3058199       -0.4872299  
DESTIN_SZTPSZ02  DESTIN_SZTPSZ03  DESTIN_SZTPSZ04  DESTIN_SZTPSZ05  
      0.7158441       -0.4314229       -1.5898245       -1.0445550  
DESTIN_SZTPSZ06  DESTIN_SZTPSZ07  DESTIN_SZTPSZ08  DESTIN_SZTPSZ09  
     -0.4319582       -2.1602303       -1.1920493       -0.2022481  
DESTIN_SZTPSZ10  DESTIN_SZTPSZ11  DESTIN_SZTPSZ12  DESTIN_SZTSSZ01  
     -1.2464793       -0.0808445       -0.6784376       -1.5845062  
DESTIN_SZTSSZ02  DESTIN_SZTSSZ03  DESTIN_SZTSSZ04  DESTIN_SZTSSZ05  
     -0.1886010        0.6525526        0.5285464        1.4670106  
DESTIN_SZTSSZ06  DESTIN_SZWCSZ01  DESTIN_SZWCSZ02  DESTIN_SZWCSZ03  
      2.5043588        1.9787931       -2.2593108       -3.1897655  
DESTIN_SZWDSZ01  DESTIN_SZWDSZ02  DESTIN_SZWDSZ03  DESTIN_SZWDSZ04  
      1.0476108       -1.3176990        0.3432057       -0.7895927  
DESTIN_SZWDSZ05  DESTIN_SZWDSZ06  DESTIN_SZWDSZ07  DESTIN_SZWDSZ08  
     -0.8751665       -0.2106221       -1.6050834       -0.5124717  
DESTIN_SZWDSZ09  DESTIN_SZYSSZ01  DESTIN_SZYSSZ02  DESTIN_SZYSSZ03  
      0.3813542        0.0853753       -0.3227172       -0.4151283  
DESTIN_SZYSSZ04  DESTIN_SZYSSZ05  DESTIN_SZYSSZ06  DESTIN_SZYSSZ07  
     -0.4637327       -1.5888242       -1.4606209       -0.7839065  
DESTIN_SZYSSZ08  DESTIN_SZYSSZ09        log(DIST)  
      0.6265412        0.1520067       -1.8468315  

Degrees of Freedom: 14470 Total (i.e. Null);  13912 Residual
Null Deviance:      47090000 
Residual Deviance: 10420000     AIC: 10510000

Model Comparison

model_list <- list(unconstrained=uncSIM,
                   originConstrained=orcSIM,
                   destinationConstrained=decSIM,
                   doublyConstrained=dbcSIM)

compare_performance(model_list,
                    metrics = "RMSE")
# Comparison of Model Performance Indices

Name                   | Model |     RMSE
-----------------------------------------
unconstrained          |   glm | 3198.736
originConstrained      |   glm | 2613.236
destinationConstrained |   glm | 2754.902
doublyConstrained      |   glm | 1906.694

Visualising Fitted

Extract the fitted values from each model

Unconstrainted Model

df <- as.data.frame(uncSIM$fitted.values) %>%
  round(digits = 0)

inter_zonal_flow <- inter_zonal_flow %>%
  cbind(df) %>%
  rename(uncTRIPS = `uncSIM.fitted.values`)

Origin Constrained Model

df <- as.data.frame(orcSIM$fitted.values) %>%
  round(digits = 0)

inter_zonal_flow <- inter_zonal_flow %>%
  cbind(df) %>%
  rename(orcTRIPS = `orcSIM.fitted.values`)

Destination Constrained Model

df <- as.data.frame(decSIM$fitted.values) %>%
  round(digits = 0)

inter_zonal_flow <- inter_zonal_flow %>%
  cbind(df) %>%
  rename(decTRIPS = `decSIM.fitted.values`)

Doubly Constrained Model

df <- as.data.frame(dbcSIM$fitted.values) %>%
  round(digits = 0)

inter_zonal_flow <- inter_zonal_flow %>%
  cbind(df) %>%
  rename(dbcTRIPS = `dbcSIM.fitted.values`)

Plotting graphs

unc_p <- ggplot(data = inter_zonal_flow,
                aes(x = uncTRIPS,
                    y = TRIPS)) +
  geom_point() +
  geom_smooth(method = lm)

orc_p <- ggplot(data = inter_zonal_flow,
                aes(x = orcTRIPS,
                    y = TRIPS)) +
  geom_point() +
  geom_smooth(method = lm)

dec_p <- ggplot(data = inter_zonal_flow,
                aes(x = decTRIPS,
                    y = TRIPS)) +
  geom_point() +
  geom_smooth(method = lm)

dbc_p <- ggplot(data = inter_zonal_flow,
                aes(x = dbcTRIPS,
                    y = TRIPS)) +
  geom_point() +
  geom_smooth(method = lm)

ggarrange(unc_p, orc_p, dec_p, dbc_p,
          ncol = 2,
          nrow = 2)
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'